<?php

use App\Http\Controllers\ArticleController;
use App\Http\Controllers\CategoryController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('/greeting', function () {
    return 'Hello World';
});

//Route::get('/greeting', function () {
//    return view('greeting');
//});

Route::get('/greeting/test', function () {
    return 'Hello World Test';
});

Route::get('/greeting/{id}', function ($id) {
    return 'Hello World 参数：' . $id;
});

Route::get('/login', [\App\Http\Controllers\LoginController::class, 'index']);
Route::post('/login', [\App\Http\Controllers\LoginController::class, 'submit']);


Route::middleware('admin')->group(function () {
    Route::get('/home', [\App\Http\Controllers\HomeController::class, 'index']);
    Route::get('/logout', [\App\Http\Controllers\HomeController::class, 'logout']);
    Route::get('/user', [\App\Http\Controllers\UserController::class, 'index']);
    Route::get('/user/password', [\App\Http\Controllers\UserController::class, 'password']);
    Route::post('/user/password', [\App\Http\Controllers\UserController::class, 'password']);
    Route::get('/user/info', [\App\Http\Controllers\UserController::class, 'userInfo']);
    Route::post('/user/info', [\App\Http\Controllers\UserController::class, 'userInfo']);
    Route::post('/user/avatar', [\App\Http\Controllers\UserController::class, 'avatar']);

    Route::prefix('category')->group(function () {
        Route::get('', [CategoryController::class, 'index']);
        Route::get('list', [CategoryController::class, 'list']);
        Route::post('', [CategoryController::class, 'store']);
        Route::patch('', [CategoryController::class, 'update']);
        Route::delete('', [CategoryController::class, 'destroy']);
        Route::get('export', [CategoryController::class, 'export']);
    });

    Route::prefix('article')->group(function () {
        Route::get('', [ArticleController::class, 'index']);
        Route::get('list', [ArticleController::class, 'list']);
        Route::post('', [ArticleController::class, 'store']);
        Route::patch('', [ArticleController::class, 'update']);
        Route::delete('', [ArticleController::class, 'destroy']);
    });
});

Route::prefix('web')->group(function () {
    Route::get('/article', [\App\Http\Controllers\Web\ArticleController::class, 'index'])->name('web.article');
    Route::get('/article/{id}', [\App\Http\Controllers\Web\ArticleController::class, 'show']);
    Route::any('/avatar', [\App\Http\Controllers\Web\AvatarController::class, 'index'])->name('web.avatar');
});

Route::prefix('manage')->group(function () {
    Route::get('/login', [\App\Http\Controllers\Manage\AuthController::class, 'index'])->name('manage.login_index');
    Route::post('/login', [\App\Http\Controllers\Manage\AuthController::class, 'submit'])->name('manage.login_submit');
    Route::get('/logout', [\App\Http\Controllers\Manage\AuthController::class, 'logout'])->name('manage.logout');
    Route::middleware('manage')
        ->get('/index', [\App\Http\Controllers\Manage\IndexController::class, 'index'])->name('manage.index');
});






